package demo.controller;

import demo.domain.City;
import demo.service.impl.CityServiceImpl;
import demo.service.impl.CityServiceBoth;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CityRestController {

    @Autowired
    private CityServiceImpl cityService;

    @Autowired
    private CityServiceBoth cityServiceBoth;

    @RequestMapping(value = "/api/city", method = RequestMethod.GET)
    public City findOneCity(@RequestParam(value = "cityName", required = true) String cityName) {
        //http://localhost:8080/api/city?cityName=Shanghai
        return cityService.findCityByName(cityName);
    }

    @RequestMapping(value = "/api/hello", method = RequestMethod.GET)
    public String helloOneCity(@RequestParam(value = "cityName", required = true) String cityName) {
        //http://localhost:8080/api/hello?cityName=Shanghai
        return "hello world." + cityName;
    }
    @RequestMapping(value = "/api/insert", method = RequestMethod.GET)
    public String insertCity() {
        //http://localhost:8080/api/insert
        cityServiceBoth.method();
        return "insert Done!";
    }
}
